package com.gjt.zyglxt.controller;

import java.util.HashMap;

import java.util.Map;

import javax.annotation.Resource;

import com.gjt.zyglxt.dao.IConsumeDao;
import com.gjt.zyglxt.dto.ConsumeDTO;
import com.gjt.zyglxt.model.Consume;
import com.gjt.zyglxt.service.IConsumeService;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * ConsumeController
 */
@RestController
@RequestMapping("/consume")
public class ConsumeController {

    @Resource
    private IConsumeDao consumeDao;
    @Resource
    private IConsumeService consumeService;
    @ApiOperation(value = "查询所有",notes = "查询所有")
    @PostMapping("/findAll")
    public Map<String,Object> findAll(@RequestBody ConsumeDTO dto){
        
        Map<String,Object> map = new HashMap<String,Object>();
        Page<Consume> p = consumeSerice.findPage(dto);
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", p.getNumberOfElements());
        map.put("data", p.getContent());
        return map;
    }

  
   /*  @ApiOperation(value = "根据id删除资源",notes = "根据id删除资源")
    @ApiImplicitParam(name = "id",value = "主键",required = true,paramType = "path")
    @DeleteMapping("/{id}")
    public void del(@PathVariable Integer id){
         consumeDao.deleteById(id);
    } */

    @Resource
    private IConsumeService consumeSerice;
    @ApiOperation(value = "刷卡",notes = "刷卡")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "readRoomId",value = "资源室编号",required = true,paramType = "path")
    })
    @PutMapping("/{readRoomId}/{cardNo}/{inOrOut}")
    public Consume ente(@PathVariable Integer readRoomId,@PathVariable String cardNo,@PathVariable Boolean inOrOut){
        return consumeSerice.swipingCard(readRoomId, cardNo, inOrOut);
    }

}